package com.anhuanjia.tools.eao.controller;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.springframework.util.StringUtils;
import com.alibaba.fastjson.JSON;
import com.anhuanjia.bean.MhBranch;
import com.anhuanjia.tools.eao.bean.EaoAppraise;
import com.anhuanjia.tools.eao.bean.EaoBuildingContent;
import com.anhuanjia.tools.eao.bean.EaoManagement;
import com.anhuanjia.tools.eao.bean.EaoPosition;
import com.anhuanjia.tools.eao.bean.EaoProductionEquipment;
import com.anhuanjia.tools.eao.bean.EaoProjectDoc;
import com.anhuanjia.tools.eao.bean.EaoProjectInfo;
import com.anhuanjia.tools.eao.bean.EaoProjectInfo2;
import com.anhuanjia.tools.eao.bean.EaoProjectStaff;
import com.anhuanjia.tools.eao.bean.EaoPublicProject;
import com.anhuanjia.tools.eao.bean.EaoPublicityQuestions;
import com.anhuanjia.tools.eao.bean.EaoPublicityURL;
import com.anhuanjia.tools.eao.bean.EaoSensitivePoints;
import com.anhuanjia.tools.eao.bean.EaoSurroundCompany;
import com.anhuanjia.tools.eao.beanvo.EaoBasicInformationVo;
import com.anhuanjia.tools.eao.beanvo.EaoBranchListVo;
import com.anhuanjia.tools.eao.beanvo.EaoBranchVo;
import com.anhuanjia.tools.eao.util.GBTUtil;
import com.efastsoft.framework.Member;
import com.efastsoft.framework.UIFacade;
import com.efastsoft.framework.UserInfo;
import com.efastsoft.framework.annotation.Alias;
import com.efastsoft.framework.annotation.Priv;
import com.efastsoft.framework.annotation.Priv.LoginType;
import com.efastsoft.framework.data.DataRow;
import com.efastsoft.framework.data.DataTable;
import com.efastsoft.framework.data.Q;
import com.efastsoft.framework.utility.StringUtil;

@Alias("ProjectInfo")
public class ProjectInfoUI extends UIFacade {
	/**
	 * @Title: findAllProject
	 * @Description: 查询全部项目
	 * @author wangqiangqiang
	 * @date 2018年9月17日下午4:39:42
	 */
	@Priv(loginType = LoginType.Member)
	public void findAllProject() {
		int pageSize = this.Request.getInt("PageSize");
		if (pageSize == 0) {
			pageSize = 10;
		}
		int pageIndex = this.Request.getInt("PageIndex");
		String Report_type = $V("ReportType");// 报告类型
		String time = $V("Time");// 时间
		String MProvince = $V("MProvince");// 省份
		String MCity = $V("MCity");// 城市
		String Project_name = $V("ProjectName");// 项目名
		String key = $V("Key");
		String order = $V("Order");
		Q q = new Q(" select * from eao_project_info where 1 = 1 and Company = ? ", Member.getCompany());

		if ("1".equals(Report_type)) {
			q.append(" and ReportType = ?", "报告表");
		} else if ("2".equals(Report_type)) {
			q.append(" and ReportType = ?", "报告书");
		} else if ("3".equals(Report_type)) {
			q.append(" and ReportType = ?", "现状评估报告");
		} else if ("4".equals(Report_type)) {
			q.append(" and ReportType = ?", "规划环评");
		} else if ("5".equals(Report_type)) {
			q.append(" and ReportType = ?", "验收报告");
		}
		if ("1".equals(time)) {
			q.append(
					" and DATE_FORMAT(PerjectTime,'%Y-%m-%d') BETWEEN date_sub(curdate(),interval 7 DAY) and curdate()");
		} else if ("2".equals(time)) {
			q.append(" and DATE_SUB(CURDATE(), INTERVAL 1 MONTH)<= DATE_FORMAT(PerjectTime,'%Y-%m-%d')");
		} else if ("3".equals(time)) {
			q.append(" and DATE_SUB(CURDATE(), INTERVAL 6 MONTH)<= DATE_FORMAT(PerjectTime,'%Y-%m-%d')");
		} else if ("4".equals(time)) {
			q.append(" and DATE_FORMAT(PerjectTime,'%Y-%m-%d') > DATE_SUB( CURDATE() , INTERVAL 12 MONTH)");
		} else if ("0".equals(time)) {
			q.append(" and 1 = 1 ");
		}
		if (StringUtil.isNotEmpty(MProvince) && StringUtil.isNotEmpty(MCity)) {
			q.append(" and BuildAddress like ?", "%" + MProvince + "%" + MCity + "%");
		}
		if (StringUtil.isNotEmpty(MProvince) && StringUtils.isEmpty(MCity)) {
			q.append(" and BuildAddress like ?", "%" + MProvince + "%");
		}
		if (StringUtil.isNotEmpty(Project_name)) {
			q.append(" and ProjectName like ?", "%" + Project_name + "%");
		}
		if (StringUtil.isNotEmpty(key) && StringUtil.isNotEmpty(order)) {
			if ("normal".equals(order)) {
				q.orderby("PerjectTime desc");
			} else {
				q.orderby("if(isnull(" + key + "),1,0)," + key + " " + order);
			}
		} else {
			q.orderby("PerjectTime desc");
		}
		DataTable projectDt = q.fetch(pageSize, pageIndex);
		DataTable projectDt1 = q.fetch();
		Integer count = projectDt1.getRowCount();
		List<EaoProjectInfo> list = new ArrayList<>();
		if (projectDt.getRowCount() > 0) {
			for (DataRow dataRow : projectDt) {
				EaoProjectInfo pi = new EaoProjectInfo();
				pi.setValue(dataRow);
				list.add(pi);
			}
		} else {
			list = null;
		}

		this.Response.put("countProjectList", count);// 用于分页总条数
		this.Response.put("projectList", list);// 分页查询
	}

	/**
	 * @Title: findAllProject
	 * @Description: 查询已完成全部项目
	 * @author wangqiangqiang
	 * @throws ParseException
	 * @date 2018年9月17日下午4:39:42
	 */
	@Priv(login = false)
	public void findAllEntProject() throws ParseException {
		int pageSize = this.Request.getInt("PageSize");
		if (pageSize == 0) {
			pageSize = 10;
		}
		int pageIndex = this.Request.getInt("PageIndex");
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
		String startTime = $V("StartTime");// 起始时间
		String endTime = $V("EndTime");// 结束时间
		DataTable dataTable2 = new Q(" select Type , ID from Ec_Member where ID = ? ", UserInfo.getID()).fetch();
		DataTable dataTable3 = new Q("select Company from Mh_Resource where Member = ?", UserInfo.getID()).fetch();
		String dataTable4 = new Q("select IsEngineer from eao_is_engineer where Member = ?", UserInfo.getID())
				.executeString();
		String Company = null;
		Boolean bl = false;
		if (dataTable2.getRowCount() != 0) {
			if ("Ent".equals(dataTable2.get(0, 0))) {
				Company = dataTable2.getString(0, 1);
				bl = true;
			}
		}
		if (!StringUtils.isEmpty(dataTable4)) {
			if ("1".equals(dataTable4) || "2".equals(dataTable4)) {
				Company = dataTable3.getString(0, 0);
				bl = true;
			}
			DataTable table = new Q("select ParentId from eao_Position where Id = ?", dataTable4).fetch();
			if (!StringUtils.isEmpty(table)) {
				if ("1".equals(table.getString(0, 0)) || "2".equals(table.getString(0, 0))) {
					Company = dataTable3.getString(0, 0);
					bl = true;
				}
			}
		}
		Q q = new Q(" select * from eao_project_info where 1 = 1 and PerjectType = 16 ");
		List<String> Project_id = new ArrayList<>();
		if (bl) {
			q.append(" and Company = ?", Company);
		} else {
			DataTable dataTable = new Q(" select ProjectId from eao_project_staff where 1 = 1 and StaffName = ?",
					UserInfo.getID()).fetch();
			if (dataTable.getRowCount() != 0) {
				for (DataRow dataRow : dataTable) {
					Project_id.add(dataRow.getString(0));
				}
			}
			if (dataTable.getRowCount() > 0) {
				q.append(" and (CreatePerson = ? or PerjectLeader = ? ", UserInfo.getID(), UserInfo.getID());
				q.or().in(" id ", Project_id);
				q.append(" ) ");
			} else {
				q.append(" and (CreatePerson = ? or PerjectLeader = ?)", UserInfo.getID(), UserInfo.getID());
			}
		}

		if (StringUtil.isNotEmpty(startTime) && StringUtil.isNotEmpty(endTime)) {
			Date startdate = sf.parse(startTime);
			Date enddate = sf.parse(endTime);
			q.append(" and DATE_FORMAT(EntTime,'%Y-%m-%d') between ? and ?", startdate, enddate);
		} else if (StringUtil.isNotEmpty(startTime) && !StringUtil.isNotEmpty(endTime)) {
			Date startdate = sf.parse(startTime);
			q.append(" and DATE_FORMAT(EntTime,'%Y-%m-%d') between ? and ?", startdate, new Date());
		} else if (!StringUtil.isNotEmpty(startTime) && StringUtil.isNotEmpty(endTime)) {
			Date enddate = sf.parse(endTime);
			q.append(" and DATE_FORMAT(EntTime,'%Y-%m-%d') <? ", enddate);
		}
		q.orderby("PerjectTime desc");
		DataTable projectDt = q.fetch(pageSize, pageIndex);
		DataTable projectDt1 = q.fetch();
		DataTable table = new Q(" select * from eao_achievements ").fetch();
		List<EaoProjectInfo> list = new ArrayList<>();
		Integer num3 = 0;
		List<String> listGrade = new ArrayList<>();
		for (DataRow dataRow : projectDt) {
			String Grade_approval = null;
			EaoProjectInfo pi = new EaoProjectInfo();
			pi.setValue(dataRow);
			if (StringUtils.isEmpty(pi.getGradeApproval())) {
				Grade_approval = "县批";
			} else if ("部批".equals(pi.getGradeApproval())) {
				Grade_approval = "省批";
			} else {
				Grade_approval = pi.getGradeApproval();
			}
			listGrade.add(Grade_approval);
			for (DataRow dr : table) {
				if ("报告书".equals(pi.getReportType())) {
					if (dr.getString("department").equals(Grade_approval) && "报告书".equals(dr.getString("ReportType"))) {
						pi.setContractAmount(dr.getString("Achievements"));
						num3 = num3 + Integer.parseInt(pi.getContractAmount());
					}
				} else if ("报告表".equals(pi.getReportType())) {
					String[] st = pi.getReportSpecialItem().split("\"");
					if (st.length == 3) {
						if ("一般报告表".equals(dr.getString("ReportType")) && "无专项".equals(dr.getString("Special"))
								&& dr.getString("Department").equals(Grade_approval)) {
							pi.setContractAmount(dr.getString("Achievements"));
							num3 = num3 + Integer.parseInt(pi.getContractAmount());
						}
					} else if (st.length == 5) {
						String report_type = new Q(" select Item from eao_report_type where ReportId = ? ", st[3])
								.executeString();
						if ("核与辐射项目报告表".equals(report_type)) {
							report_type = "核与辐射报告表";
							if (StringUtils.isEmpty(pi.getGradeApproval())) {
								Grade_approval = "市批";
							}
						}
						if (report_type.equals(dr.getString("ReportType")) && "无专项".equals(dr.getString("Special"))
								&& dr.getString("Department").equals(Grade_approval)) {
							pi.setContractAmount(dr.getString("Achievements"));
							num3 = num3 + Integer.parseInt(pi.getContractAmount());
						}
					} else {
						String report_type = new Q(" select Item from eao_report_type where ReportId = ? ", st[3])
								.executeString();
						if ("核与辐射项目报告表".equals(report_type)) {
							report_type = "核与辐射报告表";
							if (StringUtils.isEmpty(pi.getGradeApproval())) {
								Grade_approval = "市批";
							}
						}
						if (report_type.equals(dr.getString("ReportType")) && "1个专项".equals(dr.getString("special"))
								&& dr.getString("Department").equals(Grade_approval)) {
							pi.setContractAmount(dr.getString("Achievements"));
							num3 = num3 + Integer.parseInt(pi.getContractAmount());
						}
					}
				} else {
					pi.setContractAmount(dr.getString("Achievements"));
					num3 = num3 + Integer.parseInt(pi.getContractAmount());
				}
			}
			list.add(pi);
		}

		Q q1 = new Q(
				"select count(*) as Num from eao_project_info where ReportType = '报告书' and PerjectType = 16 and Company = ?",
				Member.getCompany());
		Q q2 = new Q(
				" select count(*) as Num from eao_project_info where ReportType = '报告表' and PerjectType = 16 and Company = ?",
				Member.getCompany());
		if (!bl) {
			DataTable dataTable = new Q(" select ProjectId from eao_project_staff where 1 = 1 and StaffName = ?",
					UserInfo.getID()).fetch();
			if (dataTable.getRowCount() > 0) {
				q1.append(" and (CreatePerson = ? or PerjectLeader = ? ", UserInfo.getID(), UserInfo.getID());
				q1.or().in(" Id ", Project_id);
				q1.append(" ) ");
				q2.append(" and (CreatePerson = ? or PerjectLeader = ? ", UserInfo.getID(), UserInfo.getID());
				q2.or().in(" Id ", Project_id);
				q2.append(" ) ");
			} else {
				q1.append(" and (CreatePerson = ? or PerjectLeader = ?)", UserInfo.getID(), UserInfo.getID());
				q2.append(" and (CreatePerson = ? or PerjectLeader = ?)", UserInfo.getID(), UserInfo.getID());
			}
		}
		DataTable num1 = q1.fetch();
		DataTable num2 = q2.fetch();
		Map<String, String> numMap = new HashMap<>();

		numMap.put("bgsNum", String.valueOf(num1.get(0).getString("Num")));
		numMap.put("bgbNum", String.valueOf(num2.get(0).getString("Num")));
		numMap.put("jxNum", num3.toString());
		this.Response.put("numMap", numMap);
		this.Response.put("countProjectList", projectDt1.getRowCount());// 用于分页总条数
		this.Response.put("projectList", list);// 分页查询
	}

	/**
	 * 人员管理列表查询
	 */
	@Priv(loginType = LoginType.Member)
	public void findInformation() {

		int pageSize = this.Request.getInt("PageSize");
		if (pageSize == 0) {
			pageSize = 10;
		}
		int pageIndex = this.Request.getInt("PageIndex");
		String RealName = $V("RealName");
		String name = $V("Name");
		String position = $V("Position");
		String userOrg = $V("userOrg");
		if("0".equals(userOrg)) {
			return;
		}
		List<EaoBasicInformationVo> list = new ArrayList<EaoBasicInformationVo>();
		Q peoples = new Q(
				"SELECT re.Company as BranchId,re.Member as MemberId,po.Id as PositionId,po.Position,me.RealName,me.Gender as Sex,rb.Name,rb.BranchInnerCode,rb.ParentInnerCode,rb.CompanyType,me.Mobile FROM Mh_Resource re left join Ec_Member AS me on re.Member = me.ID left join Mh_Branch AS rb on rb.Company = re.Company and rb.BranchInnerCode = re.BranchInnerCode left join eao_is_engineer eie on eie.Member = re.Member left join eao_Position po on po.Id = eie.IsEngineer where ");
		Q peopleNum = new Q(
				"SELECT count(1) as num FROM Mh_Resource re left join Ec_Member AS me on re.Member = me.ID left join Mh_Branch AS rb on rb.Company = re.Company and rb.BranchInnerCode = re.BranchInnerCode  left join eao_is_engineer eie on eie.Member = re.Member left join eao_Position po on po.Id = eie.IsEngineer where ");
		long companyId = 0;
		if ("Ent".equals(Member.getType())) {
			companyId = Member.getUID();
			peopleNum.append("re.Company = ?", companyId);
			peoples.append("re.Company = ?", companyId);
		} else {
			companyId = Member.getCompany();
			peopleNum.append("re.Company = ?", companyId);
			peoples.append("re.Company = ?", companyId);
		}
		if (StringUtil.isNotEmpty(RealName)) {
			peoples.append(" and me.RealName like ?", "%" + RealName + "%");
			peopleNum.append(" and me.RealName like ?", "%" + RealName + "%");
		}
		if (StringUtil.isNotEmpty(name)) {
			List<String> BranchInnerCode = new ArrayList<>();
			BranchInnerCode.add(name);
			DataTable dataTable = new Q(
					" select BranchInnerCode from Mh_Branch where CompanyType = 2 And ParentInnerCode = ?", name)
							.fetch();
			for (DataRow dataRow : dataTable) {
				BranchInnerCode.add(dataRow.getString(0));
			}
			peoples.and().in(" rb.BranchInnerCode", BranchInnerCode);
			peopleNum.and().in(" rb.BranchInnerCode", BranchInnerCode);
		}
		if (StringUtil.isNotEmpty(position)) {
			peoples.append(" and po.Position  like ?", "%" + position + "%");
			peopleNum.append(" and po.Position like ?", "%" + position + "%");
		}
		peoples.append(" order by rb.ParentInnerCode asc,po.Id asc ,me.RealName asc");

		DataTable dataTable = peoples.fetch(pageSize, pageIndex);
		DataTable dataNum = peopleNum.fetch();
		Set<String> set = new HashSet<>();
		List<String> setGsIds = new ArrayList<String>();
		this.Response.put("peoples", dataTable);
		if (dataTable.getRowCount() != 0) {
			for (DataRow dataRow : dataTable) {
				EaoBasicInformationVo information = new EaoBasicInformationVo();
				information.setMemberId(dataRow.getLong("MemberId"));
				information.setBrId(dataRow.getString("BranchInnerCode"));
				information.setPositionId(dataRow.getInt("PositionId"));
				information.setPosition(dataRow.getString("Position"));
				information.setRealName(dataRow.getString("RealName"));
				information.setMobile(dataRow.getString("Mobile"));
				information.setSex(dataRow.getString("Sex"));
				information.setBranch(dataRow.getString("Name"));
				information.setBranchInnerCode(dataRow.getString("BranchInnerCode"));
				information.setParentInnerCode(dataRow.getString("ParentInnerCode"));
				information.setCompanyType(dataRow.getInt("CompanyType"));
				information.setGs(dataRow.getString("Name"));
				information.setGsId(dataRow.getString("BranchInnerCode"));
				list.add(information);
				if (StringUtil.isEmpty(dataRow.getString("CompanyType"))
						|| "0".equals(dataRow.getString("CompanyType"))) {
					set.add(dataRow.getString("BranchInnerCode"));
				} else {
					set.add(dataRow.getString("ParentInnerCode"));
				}
				if (dataRow.getString("CompanyType").equals("0") || dataRow.getString("CompanyType").equals("1")) {
					setGsIds.add(dataRow.getString("BranchInnerCode"));
				}
			}

			DataTable dt = new Q("select * from Mh_Branch where 1 = 1").and().in("BranchInnerCode", set).fetch();
			for (DataRow dataRow : dt) {
				for (EaoBasicInformationVo basicInformationVo : list) {
					if (dataRow.getString("BranchInnerCode").equals(basicInformationVo.getParentInnerCode())) {
						basicInformationVo.setGsId(dataRow.getString("BranchInnerCode"));
						basicInformationVo.setGs(dataRow.getString("Name"));
						basicInformationVo.setCompanyType(dataRow.getInt("CompanyType"));
					}

				}
			}
		}
			List<EaoBranchListVo> branchList = new ArrayList<>();

			DataTable branchDt = new Q(
					" SELECT * FROM Mh_Branch WHERE (CompanyType = 0 or CompanyType = 1) AND Company = ? ", companyId)
							.fetch();
			if (branchDt.getRowCount() != 0) {
				for (DataRow dataRow : branchDt) {
					EaoBranchListVo branch = new EaoBranchListVo();
					branch.setId(dataRow.getLong("ID"));
					branch.setBranchInnerCode(dataRow.getString("BranchInnerCode"));
					branch.setCompany(dataRow.getLong("Company"));
					branch.setName(dataRow.getString("Name"));
					branch.setParentInnerCode(dataRow.getString("ParentInnerCode"));
					branch.setCompanyType(dataRow.getString("CompanyType"));
					branchList.add(branch);
				}
			}

			List<EaoBranchListVo> branchListNew = new ArrayList<>();
			DataTable branchDtNew = new Q(" SELECT * FROM Mh_Branch WHERE CompanyType = 2 AND Company = ? ", companyId)
					.fetch();
			if (branchDtNew.getRowCount() != 0) {
				for (DataRow dataRow : branchDtNew) {
					EaoBranchListVo branch = new EaoBranchListVo();
					branch.setId(dataRow.getLong("ID"));
					branch.setBranchInnerCode(dataRow.getString("BranchInnerCode"));
					branch.setCompany(dataRow.getLong("Company"));
					branch.setName(dataRow.getString("Name"));
					branch.setParentInnerCode(dataRow.getString("ParentInnerCode"));
					branch.setCompanyType(dataRow.getString("CompanyType"));
					branchListNew.add(branch);
				}
				for (EaoBranchListVo branch : branchListNew) {
					for (int i = 0; i < list.size(); i++) {
						if (branch.getParentInnerCode().equals(list.get(i).getGsId())) {
							list.get(i).getBranchList().add(branch);
						}
					}
				}
			}
			this.Response.put("branch", branchList);

			List<MhBranch> companyList = new ArrayList<>();
			DataTable company = new Q(" SELECT * FROM Mh_Branch WHERE CompanyType IN (0,1) AND Company = ? ", companyId)
					.fetch();
			if (company.getRowCount() != 0) {
				for (DataRow dataRow : company) {
					MhBranch branch = new MhBranch();
					branch.setValue(dataRow);
					companyList.add(branch);
				}
			}
			this.Response.put("company", companyList);
			List<EaoPosition> bumenList = new ArrayList<EaoPosition>();
			DataTable bumen = new Q(
					" SELECT Id,`Position`,`Type`,ParentId FROM eao_Position where (Type = ? or Type is null) and Id not in (SELECT ParentId FROM eao_Position where Type = ? and ParentId is not null) ",
					companyId, companyId).fetch();
			if (bumen.getRowCount() != 0) {
				for (DataRow dataRow : bumen) {
					EaoPosition po = new EaoPosition();
					po.setId(dataRow.getInt("Id"));
					if (dataRow.getInt("Id") > 8) {
						po.setParentId(dataRow.getInt("ParentId"));
					} else {
						po.setParentId(dataRow.getInt("Id"));
					}
					po.setPosition(dataRow.getString("Position"));
					po.setType(dataRow.getLong("Type"));
					bumenList.add(po);
				}
			}
			this.Response.put("position", bumenList);
		int num = 0;
		for (DataRow dataRow : dataNum) {
			num = dataRow.getInt("Num");
		}
		this.Response.put("information", list);
		this.Response.put("num", num);
	}

	/**
	 * 联系人列表
	 */
	@Priv(loginType = LoginType.Member)
	public void contactsMenu() {
		DataTable dt = null;
		if (Member.getType().equals("Ent")) {
			dt = new Q(
					"select mb.* from Mh_Branch mb left join Ec_Member mr on mb.Company = mr.ID  where mr.ID = ? order by mb.CompanyType desc,mb.AddTime",
					Member.getUID()).fetch();
		} else {
			dt = new Q(
					"select mb.* from Mh_Branch mb left join Mh_Resource mr on mb.Company = mr.Company  where mr.Member = ? order by mb.CompanyType desc,mb.AddTime",
					Member.getUID()).fetch();
		}
		List<EaoBranchVo> hmList = new ArrayList<>();
		String branchInnerCode = "";
		for (DataRow dataRow : dt) {
			EaoBranchVo hm = new EaoBranchVo();
			hm.setId(dataRow.getString("BranchInnerCode"));
			hm.setTitle(dataRow.getString("Name"));
			hm.setCompany(dataRow.getLong("Company"));
			hm.setParentId(dataRow.getString("ParentInnerCode"));
			hm.setCompanyType(dataRow.getString("CompanyType"));
			if ("0".equals(hm.getCompanyType())) {
				branchInnerCode = dataRow.getString("ParentInnerCode");
			}
			hmList.add(hm);
		}
		Q q = new Q(
				"select em.ID,mr.Company,mr.BranchInnerCode,em.RealName from Mh_Resource mr left join Ec_Member em on em.ID = mr.Member where 1=1");
		q.and().eq("mr.Company", Member.getCompany());
		DataTable branchListTemp = q.fetch();
		if (dt.getRowCount() > 0) {
			for (DataRow dataRow : branchListTemp) {
				EaoBranchVo branch = new EaoBranchVo();
				branch.setId(dataRow.getString("ID"));
				branch.setCompany(dataRow.getLong("Company"));
				branch.setParentId(dataRow.getString("BranchInnerCode"));
				branch.setTitle(dataRow.getString("RealName"));
				branch.setCompanyType("4");
				hmList.add(branch);
			}
		}

		List<EaoBranchVo> hmTree = contactsTree(hmList, branchInnerCode);
		$S("branchTree", JSON.toJSON(hmTree));
	}

	public static List<EaoBranchVo> contactsTree(List<EaoBranchVo> list, String parentId) {
		List<EaoBranchVo> menus = new ArrayList<EaoBranchVo>();
		for (EaoBranchVo menu : list) {
			String menuId = menu.getId();
			String pid = menu.getParentId();
			if (parentId.equals(pid)) {
				List<EaoBranchVo> menuLists = contactsTree(list, menuId);
				menu.setChildren(menuLists);
				menus.add(menu);
			}
		}
		return menus;
	}

	/**
	 * 查询所有管理名录菜单列表
	 */
	@Priv(loginType = LoginType.Member)
	public void findAllMenu2() {
		DataTable dt = new Q(" select * from eao_management where Father = ' ' or Father is null ORDER BY sort").fetch();
		List<Map<String, Object>> list = new ArrayList<>();
		for (DataRow dataRow : dt) {
			EaoManagement management = new EaoManagement();
			management.setValue(dataRow);
			Map<String, Object> reportTypeVo = new HashMap<>();
			reportTypeVo.put("value", management.getMid());
			reportTypeVo.put("label", management.getMid() + " " + management.getType());
			list.add(reportTypeVo);
			List<Map<String, Object>> reportTypeVo2List = new ArrayList<>();
			DataTable dt2 = new Q(" select * from eao_management where Father = ? ORDER BY sort", management.getMid()).fetch();
			if (dt2.getRowCount() > 0) {
				for (DataRow dataRow2 : dt2) {
					EaoManagement management2 = new EaoManagement();
					management2.setValue(dataRow2);
					Map<String, Object> reportTypeVo2 = new HashMap<>();
					reportTypeVo2.put("value", management2.getMid());
					reportTypeVo2.put("label", management2.getMid() + " " + management2.getType());
					reportTypeVo2List.add(reportTypeVo2);
					List<Map<String, Object>> reportTypeVo3List = new ArrayList<>();

					if (!reportTypeVo3List.isEmpty()) {
						reportTypeVo2.put("children", reportTypeVo3List);
					}
				}
			}
			if (!reportTypeVo2List.isEmpty()) {
				reportTypeVo.put("children", reportTypeVo2List);
			}
			this.Response.put("data", list);
		}
	}

	/**
	 * @Title: findProjectByID
	 * @Description: 通过项目id查询单个项目
	 * @author wangqiangqiang
	 * @date 2018年9月17日下午4:39:36
	 */
	@Priv(login = false)
	public void findProjectByID() {
		String id = $V("Id");
		String Economy = $V("Economy");
		if (StringUtil.isNotEmpty(id)) {
			DataTable infoDt = new Q(" select * from eao_project_info where Id = ?", id).fetch();
			DataTable docDt = new Q(" select * from eao_project_doc where ProjectId = ?", id).fetch();

			DataTable publicProjectDt = new Q("select * from eao_public_project").where().in("ProjectId", id).fetch();
			DataTable buildingContentDt = new Q("select * from eao_building_content ").where().in("ProjectId", id)
					.fetch();
			DataTable equipmentDt = new Q("select * from eao_production_equipment ").where().in("ProjectId", id)
					.fetch();
			DataTable pointsDt = new Q("select * from eao_sensitive_points").where().in("ProjectId", id).fetch();
			DataTable surroundCompanyDt = new Q("select * from eao_surround_company").where().in("ProjectId", id)
					.fetch();
			DataTable appraiseDt = new Q("select * from eao_appraise").where().in("ProjectId", id)
					.append("ORDER BY AuditTime asc").fetch();
			DataTable publicityQuestionsDt = new Q("select * from eao_publicity_questions").where().in("ProjectId", id)
					.fetch();

			DataTable publicityURL = new Q("select * from eao_publicity_url where ProjectId = ?", id).fetch();

			if (infoDt.getRowCount() != 0 && docDt.getRowCount() != 0) {
				EaoProjectInfo info = new EaoProjectInfo();
				info.setValue(infoDt.get(0));
				if (StringUtils.isEmpty(info.getReportSpecialItem())) {
					info.setReportSpecialItem("[]");
				}
				if (StringUtils.isEmpty(info.getEconomyIndustryType())) {
					info.setEconomyIndustryType("[]");
				}
				if ("Economy".equals(Economy)) {
					info.setEconomyIndustryType(GBTUtil.getname(info.getEconomyIndustryType()));
				}
				if (StringUtils.isEmpty(info.getEiaAssessCategory())) {
					info.setEiaAssessCategory("[]");
				}
				EaoProjectDoc doc = new EaoProjectDoc();
				doc.setValue(docDt.get(0));

				String projectNumber = info.getProjectNumber();
				DataTable infoDt2 = new Q(
						" select * from eao_project_info2 where ProjectNumber= ? order by UpdateTime desc",
						projectNumber).fetch();
				List<EaoProjectInfo2> projectInfo2List = new LinkedList<EaoProjectInfo2>();
				for (DataRow dataRow : infoDt2) {
					EaoProjectInfo2 pt2 = new EaoProjectInfo2();
					pt2.setValue(dataRow);
					projectInfo2List.add(pt2);
				}

				List<EaoPublicProject> publicProjectList = new ArrayList<EaoPublicProject>();
				if (publicProjectDt.getRowCount() != 0) {
					for (DataRow dataRow : publicProjectDt) {
						EaoPublicProject publicProject = new EaoPublicProject();
						publicProject.setValue(dataRow);
						publicProjectList.add(publicProject);
					}
				}
				List<EaoBuildingContent> buildingContentList = new ArrayList<EaoBuildingContent>();
				if (buildingContentDt.getRowCount() != 0) {
					for (DataRow dataRow : buildingContentDt) {
						EaoBuildingContent buildingContent = new EaoBuildingContent();
						buildingContent.setValue(dataRow);
						buildingContentList.add(buildingContent);
					}
				}
				List<EaoProductionEquipment> equipmentList = new ArrayList<EaoProductionEquipment>();
				if (equipmentDt.getRowCount() != 0) {
					for (DataRow dataRow : equipmentDt) {
						EaoProductionEquipment equipment = new EaoProductionEquipment();
						equipment.setValue(dataRow);
						equipmentList.add(equipment);
					}
				}

				List<EaoSensitivePoints> pointsList = new ArrayList<EaoSensitivePoints>();
				if (pointsDt.getRowCount() != 0) {
					for (DataRow dataRow : pointsDt) {
						EaoSensitivePoints points = new EaoSensitivePoints();
						points.setValue(dataRow);
						pointsList.add(points);
					}
				}

				List<EaoSurroundCompany> surroundCompanyList = new ArrayList<EaoSurroundCompany>();
				if (surroundCompanyDt.getRowCount() != 0) {
					for (DataRow dataRow : surroundCompanyDt) {
						EaoSurroundCompany surroundCompany = new EaoSurroundCompany();
						surroundCompany.setValue(dataRow);
						surroundCompanyList.add(surroundCompany);
					}
				}

				List<EaoAppraise> appraiseList = new ArrayList<EaoAppraise>();
				if (appraiseDt.getRowCount() != 0) {
					for (DataRow dataRow : appraiseDt) {
						EaoAppraise appraise = new EaoAppraise();
						appraise.setValue(dataRow);
						appraiseList.add(appraise);
					}
				}

				List<EaoPublicityQuestions> publicityQuestionsList = new ArrayList<EaoPublicityQuestions>();
				if (publicityQuestionsDt.getRowCount() != 0) {
					for (DataRow dataRow : publicityQuestionsDt) {
						EaoPublicityQuestions publicityQuestions = new EaoPublicityQuestions();
						publicityQuestions.setValue(dataRow);
						publicityQuestionsList.add(publicityQuestions);
					}
				}

				DataTable data = new Q("select * from eao_project_staff where ProjectId = ? and StaffName <> ?", id,
						info.getPerjectLeader()).fetch();
				List<EaoProjectStaff> projectStaff = new ArrayList<>();

				for (DataRow dataRow : data) {
					EaoProjectStaff staff = new EaoProjectStaff();
					staff.setValue(dataRow);
					projectStaff.add(staff);
				}

				List<EaoPublicityURL> publicityURLlist = new ArrayList<>();
				for (DataRow dataRow : publicityURL) {
					EaoPublicityURL url = new EaoPublicityURL();
					url.setValue(dataRow);
					publicityURLlist.add(url);
				}

				if (!StringUtils.isEmpty(info.getPerjectLeader())) {
					String Member = new Q(" select RealName from Ec_Member where Id = ?", info.getPerjectLeader())
							.executeString();
					this.Response.put("PerjectLeader", Member);
				}
				DataTable Company = new Q(" select FullName from Crm_Company where Id = ?", info.getCompany()).fetch();
				this.Response.put("info", info);
				this.Response.put("projectStaff", projectStaff);
				this.Response.put("FullName", Company.get(0, 0));
				this.Response.put("doc", doc);
				this.Response.put("pt2List", projectInfo2List);
				$S("publicProjectList", publicProjectList);
				$S("buildingContentList", buildingContentList);
				$S("equipmentList", equipmentList);
				$S("pointsList", pointsList);
				$S("surroundCompanyList", surroundCompanyList);
				$S("appraiseList", appraiseList);
				$S("publicityQuestionsList", publicityQuestionsList);
				$S("publicityURLlist", publicityURLlist);

			} else {
				f("项目未找到");
			}
		}
	}
}
